program CopyObs

    use iasing_osse
    use netcdf

    implicit none
    integer         :: inid, ouid
    type(r4a_ids)   :: in_ids, ou_ids

    integer         :: nocl, natm

    integer, allocatable    :: ocl(:)
    real(JPR4), allocatable :: dat(:,:)
    
    character(len=128)  	 :: arg(2)
    

    include "checknc.interface"
    include "r60_initializer.interface"


    call get_command_argument(1,arg(1))
    call get_command_argument(2,arg(2))
    call checknc(nf90_open(arg(1), NF90_NOWRITE, inid))
    in_ids = r60_initializer(inid)
    call checknc(nf90_open(arg(2), NF90_WRITE, ouid))
    ou_ids = r60_initializer(ouid)


    call checknc(nf90_inquire_dimension(inid, in_ids%atm_did, len=natm))
    call checknc(nf90_inquire_dimension(inid, in_ids%ocl_did, len=nocl))

    allocate(ocl(nocl))
    allocate(dat(nocl,natm))

    ! OCL
    call checknc(nf90_get_var(in_ids%dim%gid, in_ids%dim%ocl, ocl))
    print*, ocl
    call checknc(nf90_put_var(ou_ids%dim%gid, ou_ids%dim%ocl, ocl))
    print*, "ocl OK"

    ! OBT
    call checknc(nf90_get_var(in_ids%obs%gid, in_ids%obs%obt, dat))
    print*, dat(1,1)
    call checknc(nf90_put_var(ou_ids%obs%gid, ou_ids%obs%obt, dat))
    call checknc(nf90_get_var(ou_ids%obs%gid, ou_ids%obs%obt, dat))
    print*, dat(1,1)
    print*, "obt OK"

    ! FGD
    call checknc(nf90_get_var(in_ids%obs%gid, in_ids%obs%ofd, dat))
    print*, dat(1,1)
    dat = -999.9
    call checknc(nf90_put_var(ou_ids%obs%gid, ou_ids%obs%ofd, dat))
    call checknc(nf90_get_var(ou_ids%obs%gid, ou_ids%obs%ofd, dat))
    print*, dat(1,1)
    print*, "ofd OK"

    ! OBI
    call checknc(nf90_get_var(in_ids%obs%gid, in_ids%obs%obi, dat))
    print*, dat(1,1)
    dat = -999.9
    call checknc(nf90_put_var(ou_ids%obs%gid, ou_ids%obs%obi, dat))
    call checknc(nf90_get_var(ou_ids%obs%gid, ou_ids%obs%obi, dat))
    print*, dat(1,1)
    print*, "obi OK"


end program
